//刷新页面不出错
var timer = setTimeout(function() {
    var one = document.querySelector('.one');
    var two = document.querySelector('.two');
    var date = new Date();
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var dates = date.getDate();
    var arr = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六', ];
    var day = arr[date.getDay()];
    one.innerHTML = (year + '年' + month + '月' + dates + '日 ' + day);
    two.innerHTML = (getTime());
    clearInterval(timer);

});
//设置定时器
setInterval(function() {
    //格式化日期 年月日
    var one = document.querySelector('.one');
    var two = document.querySelector('.two');
    var date = new Date();
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var dates = date.getDate();
    var arr = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六', ];
    var day = arr[date.getDay()];
    one.innerHTML = (year + '年' + month + '月' + dates + '日 ' + day);
    two.innerHTML = (getTime());
}, 1000);



//要求封装一个函数返回当前的时分秒 格式：08：08：08
function getTime() {
    var time = new Date();
    var h = time.getHours();
    h = h < 10 ? '0' + h : h;
    var m = time.getMinutes();
    m = m < 10 ? '0' + m : m;
    var s = time.getSeconds();
    s = s < 10 ? '0' + s : s;
    return h + ':' + m + ':' + s;
}